package com.yyym.foundation.redis.config;

import com.yyym.common.env.Profile;
import com.yyym.common.env.Profile.Dev;
import com.yyym.common.env.Profile.Local;
import com.yyym.common.env.Profile.Prod;
import com.yyym.common.env.Profile.Test;
import com.yyym.foundation.redis.env.RedisStructure.Cluster;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.time.Duration;
import java.util.Arrays;

/**
 * @author ymding
 */
@Configuration
@Cluster
@Profile.Cluster
public class ClusterRedisConfig extends RedisCommonConfig {

    @Bean
    @Local
    @Primary
    public RedisProperties localRedisProperties() {
        RedisProperties redisProperties = new RedisProperties();
        redisProperties.setConnectTimeout(Duration.ofSeconds(5));
        redisProperties.setTimeout(Duration.ofSeconds(30));
        RedisProperties.Cluster cluster = new RedisProperties.Cluster();
        cluster.setNodes(Arrays.asList(""));
        redisProperties.setCluster(cluster);
        return redisProperties;
    }

    @Bean
    @Dev
    @Primary
    public RedisProperties devRedisProperties() {
        RedisProperties redisProperties = new RedisProperties();
        redisProperties.setConnectTimeout(Duration.ofSeconds(5));
        redisProperties.setTimeout(Duration.ofSeconds(30));
        RedisProperties.Cluster cluster = new RedisProperties.Cluster();
        cluster.setNodes(Arrays.asList(""));
        return redisProperties;
    }

    @Bean
    @Test
    @Primary
    public RedisProperties testRedisProperties() {
        RedisProperties redisProperties = new RedisProperties();
        redisProperties.setConnectTimeout(Duration.ofSeconds(5));
        redisProperties.setTimeout(Duration.ofSeconds(10));
        RedisProperties.Cluster cluster = new RedisProperties.Cluster();
        cluster.setNodes(Arrays.asList(""));
        return redisProperties;
    }

    @Bean
    @Prod
    @Primary
    public RedisProperties prodRedisProperties() {
        RedisProperties redisProperties = new RedisProperties();
        redisProperties.setConnectTimeout(Duration.ofSeconds(2));
        redisProperties.setTimeout(Duration.ofSeconds(5));
        RedisProperties.Cluster cluster = new RedisProperties.Cluster();
        cluster.setNodes(Arrays.asList(""));
        return redisProperties;
    }

}
